/*
Copyright (C) 2009  Raymond Jeon
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/





#include "gl_lib_include.h"
#include "gl_smmp_func.h"
#include "gl_smmp_funcspam.h"
#include "gl_smmp_funcuser.h"
#include "gl_smmp_response.h"
#include "gl_mail_define.h"
#include "gl_mail_log.h"
#include "gl_mail_usercheck.h"
#include "gl_mail_user.h"
#include "gl_mail_config.h"
#include "gl_mail_statistics.h"





void GlSmmpFuncViewConfig(glsmmpsession_ *gsn, char *szVal)
{
	GlSocketStreamPrintfLnLog(gsn->stream, GlLogSmmp, "+OK List of basic configuration");
	GlSocketStreamPrintfLnLog(gsn->stream, GlLogSmmp, "ServerName            %s", __SZ(glData.szServerName));
	GlSocketStreamPrintfLnLog(gsn->stream, GlLogSmmp, "MailHostName          %s", __SZ(glData.szMailHostName));
	GlSocketStreamPrintfLnLog(gsn->stream, GlLogSmmp, "Postmaster            %s", __SZ(glData.szPostmaster));
	GlSocketStreamPrintfLnLog(gsn->stream, GlLogSmmp, "LogVerbos             %d", glData.uiLogVerbos);
	GlSocketStreamPrintfLnLog(gsn->stream, GlLogSmmp, "LogMerge              %s", glData.bLogMerge ? "on" : "off");
	GlSocketStreamPrintfLnLog(gsn->stream, GlLogSmmp, "LogExpire             %d [days]", glData.uiLogExpire);
	GlSocketStreamPrintfLnLog(gsn->stream, GlLogSmmp, "StatExpire            %d [days]", glData.uiStatExpire);
	GlSocketStreamPrintfLnLog(gsn->stream, GlLogSmmp, "OrphanMailExpire      %d [days]", glData.uiOrphanExpire);
	GlSocketStreamPrintfLnLog(gsn->stream, GlLogSmmp, "MaxMailSize           %d [bytes]", glData.uiSmtpMaxSize);
	GlSocketStreamPrintfLnLog(gsn->stream, GlLogSmmp, "SmtpMinThread         %d", glData.thSmtp.iMin);
	GlSocketStreamPrintfLnLog(gsn->stream, GlLogSmmp, "SmtpMaxThread         %d", glData.thSmtp.iMax);
	GlSocketStreamPrintfLnLog(gsn->stream, GlLogSmmp, "Pop3MinThread         %d", glData.thPop3.iMin);
	GlSocketStreamPrintfLnLog(gsn->stream, GlLogSmmp, "Pop3MaxThread         %d", glData.thPop3.iMax);
	GlSocketStreamPrintfLnLog(gsn->stream, GlLogSmmp, "SmmpMinThread         %d", glData.thSmmp.iMin);
	GlSocketStreamPrintfLnLog(gsn->stream, GlLogSmmp, "SmmpMaxThread         %d", glData.thSmmp.iMax);
	GlSocketStreamPrintfLnLog(gsn->stream, GlLogSmmp, "MtaMinThread          %d", glData.thMta.iMin);
	GlSocketStreamPrintfLnLog(gsn->stream, GlLogSmmp, "MtaMaxThread          %d", glData.thMta.iMax);
	GlSocketStreamPrintfLnLog(gsn->stream, GlLogSmmp, "SpoolingInterval      %d [mins]", glData.uiMtaSpoolInterval);
	GlSocketStreamPrintfLnLog(gsn->stream, GlLogSmmp, "MaxSpooling           %d [times]", glData.uiMtaSpoolMaxTry);
	GlSocketStreamPrintfLnLog(gsn->stream, GlLogSmmp, "MaxSpoolingReturnMail %d [times]", glData.uiMtaReturnMaxTry);
	GlSocketStreamPrintfLnLog(gsn->stream, GlLogSmmp, "RejectRelay           %s", glData.bRejectRelay ? "on" : "off");
	GlSocketStreamPrintfLnLog(gsn->stream, GlLogSmmp, "TimeZone              %s", glData.szTimeZone);
}




void GlSmmpFuncSetServerName(glsmmpsession_ *gsn, char *szVal)		
{
	glSmmpFuncError(gsn, GlMailConfigSetFieldString("ServerName", szVal, &(glData.szServerName)));
}

void GlSmmpFuncSetMailHostName(glsmmpsession_ *gsn, char *szVal)		
{
	glSmmpFuncError(gsn, GlMailConfigSetFieldString("MailHostName", szVal, &(glData.szMailHostName)));
}

void GlSmmpFuncSetPostmaster(glsmmpsession_ *gsn, char *szVal)		
{
	glSmmpFuncError(gsn, GlMailConfigSetFieldString("Postmaster", szVal, &(glData.szPostmaster)));
}

void GlSmmpFuncSetLogExpire(glsmmpsession_ *gsn, char *szVal)			
{
	glSmmpFuncError(gsn, GlMailConfigSetFieldNum("LogExpire", GlAtoiRange(szVal, 0, 1000), &((int)glData.uiLogExpire)));
}

void GlSmmpFuncSetLogVerbos(glsmmpsession_ *gsn, char *szVal)			
{
	glSmmpFuncError(gsn, GlMailConfigSetFieldNum("LogVerbos", GlAtoiRange(szVal, 1, 5), &((int)glData.uiLogVerbos)));
}

void GlSmmpFuncSetLogMerge(glsmmpsession_ *gsn, char *szVal)			
{
	glSmmpFuncError(gsn, GlMailConfigSetFieldBool("LogMerge", !stricmp(szVal, "on"), &(glData.bLogMerge)));
}

void GlSmmpFuncSetStatExpire(glsmmpsession_ *gsn, char *szVal)		
{
	glSmmpFuncError(gsn, GlMailConfigSetFieldNum("StatExpire", GlAtoiRange(szVal, 0, 1000), &((int)glData.uiStatExpire)));
}

void GlSmmpFuncSetOrphanMailExpire(glsmmpsession_ *gsn, char *szVal)	
{
	glSmmpFuncError(gsn, GlMailConfigSetFieldNum("OrphanExpire", GlAtoiRange(szVal, 0, 1000), &((int)glData.uiOrphanExpire)));
}

void GlSmmpFuncSetMaxMailSize(glsmmpsession_ *gsn, char *szVal)		
{
	glSmmpFuncError(gsn, GlMailConfigSetFieldNum("MaxMailSize", GlAtoiRange(szVal, 0, 1000000000), &((int)glData.uiSmtpMaxSize)));
}

void GlSmmpFuncSetSmtpMinThread(glsmmpsession_ *gsn, char *szVal)		
{
	glSmmpFuncError(gsn, GlMailConfigSetFieldNum("SmtpMinThread", GlAtoiRange(szVal, 2, 1000), &((int)glData.thSmtp.iMin)));
}

void GlSmmpFuncSetSmtpMaxThread(glsmmpsession_ *gsn, char *szVal)		
{
	glSmmpFuncError(gsn, GlMailConfigSetFieldNum("SmtpMaxThread", GlAtoiRange(szVal, 2, 1000), &((int)glData.thSmtp.iMax)));
}

void GlSmmpFuncSetPop3MinThread(glsmmpsession_ *gsn, char *szVal)		
{
	glSmmpFuncError(gsn, GlMailConfigSetFieldNum("Pop3MinThread", GlAtoiRange(szVal, 2, 1000), &((int)glData.thPop3.iMin)));
}

void GlSmmpFuncSetPop3MaxThread(glsmmpsession_ *gsn, char *szVal)		
{
	glSmmpFuncError(gsn, GlMailConfigSetFieldNum("Pop3MaxThread", GlAtoiRange(szVal, 2, 1000), &((int)glData.thPop3.iMax)));
}

void GlSmmpFuncSetSmmpMinThread(glsmmpsession_ *gsn, char *szVal)		
{
	glSmmpFuncError(gsn, GlMailConfigSetFieldNum("SmmpMinThread", GlAtoiRange(szVal, 2, 1000), &((int)glData.thSmmp.iMin)));
}

void GlSmmpFuncSetSmmpMaxThread(glsmmpsession_ *gsn, char *szVal)		
{
	glSmmpFuncError(gsn, GlMailConfigSetFieldNum("SmmpMaxThread", GlAtoiRange(szVal, 2, 1000), &((int)glData.thSmmp.iMax)));
}

void GlSmmpFuncSetMtaMinThread(glsmmpsession_ *gsn, char *szVal)		
{
	glSmmpFuncError(gsn, GlMailConfigSetFieldNum("MtaMinThread", GlAtoiRange(szVal, 2, 1000), &((int)glData.thMta.iMin)));
}

void GlSmmpFuncSetMtaMaxThread(glsmmpsession_ *gsn, char *szVal)		
{
	glSmmpFuncError(gsn, GlMailConfigSetFieldNum("MtaMaxThread", GlAtoiRange(szVal, 2, 1000), &((int)glData.thMta.iMax)));
}

void GlSmmpFuncSetSpoolingInterval(glsmmpsession_ *gsn, char *szVal)	
{
	glSmmpFuncError(gsn, GlMailConfigSetFieldNum("SpoolingInterval", GlAtoiRange(szVal, 1, 60*24), &((int)glData.uiMtaSpoolInterval)));
}

void GlSmmpFuncSetMaxSpooling(glsmmpsession_ *gsn, char *szVal)		
{
	glSmmpFuncError(gsn, GlMailConfigSetFieldNum("MaxSpooling", GlAtoiRange(szVal, 1, 100), &((int)glData.uiMtaSpoolMaxTry)));
}

void GlSmmpFuncSetMaxSpoolingReturnMail(glsmmpsession_ *gsn, char *szVal)
{
	glSmmpFuncError(gsn, GlMailConfigSetFieldNum("SpoolingReturnMail", GlAtoiRange(szVal, 1, 100), &((int)glData.uiMtaReturnMaxTry)));
}

void GlSmmpFuncSetRejectRelay(glsmmpsession_ *gsn, char *szVal)		
{
	glSmmpFuncError(gsn, GlMailConfigSetFieldBool("RejectRelay", !stricmp(szVal, "on"), &(glData.bRejectRelay)));
}

void GlSmmpFuncSetTimeZone(glsmmpsession_ *gsn, char *szVal)			
{
	glSmmpFuncError(gsn, GlMailConfigSetFieldString("TimeZone", szVal, &(glData.szTimeZone)));
}


